

use "$project\manager\cvrnryear_fe_over5", clear

merge 1:1 cvrnr year using "$project\merger_cvrnr", keepus(nworker) keep(1 3) nogen
drop if nworker==.
drop if nworker==1

reghdfe fe , absorb(i.cvrnr i.year) res(temp)
ren fe fe0
ren temp fe

bysort pnr cvrnr: gen nyear=_N
collapse fe nworker year nyear, by (cvrnr pnr)

gsort pnr -nyear -year
by pnr: gen count=_n
by pnr: egen nworker_total=sum(nworker*(count<=2))
gen temp=fe if count==2
bysort pnr: egen fe2=mean(temp)

sort cvrnr year
by cvrnr: gen fe_placebo=fe[_n-1] if year-year[_n-1]>2

reg fe2 fe if count==1
reg fe2 fe_p if count==1

binscatter fe2 fe if count==1, xtitle("Average residual in first firm") ytitle("Average residual in second firm")
binscatter fe2 fe_placebo if count==1, xtitle("Placebo residual in first firm") ytitle("Average residual in second firm")
